/**
 * @file webpack 配置文件
 * @author fanxingguang@baidu.com
 */

var fs = require('fs');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var nodeModules = {};
fs.readdirSync('node_modules').filter(function (x) {
        return ['.bin'].indexOf(x) === -1;
    })
    .forEach(function (mod) {
        nodeModules[mod] = 'commonjs ' + mod;
    });

var webOptions = {
    target: 'electron',
    context: __dirname + '/src',
    entry: {
        app: './index.js'
    },
    output: {
        path: __dirname + '/dist/',
        filename: 'renderer.js',
        publicPath: './'
    },
    resolve: {
        extensions: ['.js', '.vue', '.json'],
        alias: {
            vue$: 'vue/dist/vue.esm.js'
        },
        modules: [
            'node_modules', 'node_modules/dist'
        ]
    },
    module: {
        rules: [{
            test: /\.vue$/,
            loader: 'vue-loader',
            options: {
                postcss: [require('autoprefixer')({
                    browsers: ['last 2 versions']
                })],
                loaders: {
                    css: ExtractTextPlugin.extract({
                        use: 'css-loader',
                        fallback: 'vue-style-loader'
                    }),
                    less: ExtractTextPlugin.extract({
                        use: 'css-loader!less-loader',
                        fallback: 'vue-style-loader'
                    })
                }
            }
        }, 
        // {
        //     test: /\.js$/,
        //     loader: 'babel-loader'
        // }, 
        {
            test: /\.css$/,
            use: ExtractTextPlugin.extract({
                fallback: 'style-loader',
                use: 'css-loader'
            })
        }, {
            test: /\.(png|jpg|gif|ico)/,
            loader: 'file-loader?name=[path][name].[ext]'
        }, {
            test: /\.(ttf|woff|woff2|eot|svg)/,
            loader: 'file-loader?name=[path][name].[ext]'
        }]
    },
    plugins: [
        new ExtractTextPlugin('style.css')
    ]
};

module.exports = webOptions;
